#ifndef PARSE_CFG_TASK_H
#define PARSE_CFG_TASK_H

#include "lwip/netifapi.h"
#include "lwip/tcpip.h"


#define PARSE_CFG_TASK_PRIORITY    10
#define PARSE_CFG_TASK_STACK_SIZE  8000



#define PARSE_CFG_SUCCESS			0
#define PARSE_CFG_FILE_ERROR		1




#define OPC_UA_ACCESS_MAX    255
#define MODBUS_READ_MAX      255
#define MODBUS_WRITE_MAX     255

#define JSON_STRING_MAX      50


enum UART_MODE
{
      RS232=0, RS485
};


enum UART_PARITY_MODE
{
      PARITY_NONE=0, PARITY_ODD, PARITY_EVEN
};



//For communication configurtion
typedef struct
{
	uint32_t server_ip;
	uint32_t server_netmask;
	uint32_t server_gateway;
	uint32_t server_dns;
	uint32_t port;
	

}OPCUA_SERVER_COMMUN_STRUC_T;


typedef struct
{
	uint32_t parity;
	uint32_t stopbit;
	uint32_t uart_mode;		//RS232 or RS485
	uint32_t timeout;
	uint32_t dataBitsCount;
	uint32_t baudrate;
	
}MODBUS_COMMUN_STRUC_T;


typedef struct
{
	char  ntp_url[JSON_STRING_MAX];
	uint32_t poll_time;		//Uint S

}NTP_COMMUN_STRUC_T;


typedef struct
{
	OPCUA_SERVER_COMMUN_STRUC_T opcua_server_comm;
	MODBUS_COMMUN_STRUC_T modbus_comm;
	NTP_COMMUN_STRUC_T ntp_comm;

}CFG_COMMUN_STRUC_T;

//For OPC_UA_Access

typedef struct
{
	int32_t type;
	uint8_t mode;		//0: read, 1:write
	char  name[JSON_STRING_MAX];
	uint32_t position;
	uint32_t length;

}OPC_UA_Table_STRUC_T;

typedef struct
{
	uint32_t table_number;
	OPC_UA_Table_STRUC_T opcua_table[OPC_UA_ACCESS_MAX];

}OPC_UA_ACCESS_STRUC_T;



//For MODBUS_READ

typedef struct
{
	uint32_t slave_id;
	uint32_t fc;
	uint32_t address;
	uint32_t npoint;
	uint32_t poll_time;
	uint32_t max_error;
	uint32_t position;
	uint32_t start_bit;
	uint32_t swap;
	uint32_t swapword;	

}READ_TABLE_STRUC_T;

typedef struct
{
	uint32_t table_number;
	READ_TABLE_STRUC_T read_table[MODBUS_READ_MAX];

}MODBUS_READ_STRUC_T;



//For MODBUS_WRITE

typedef struct
{
	uint32_t slave_id;
	uint32_t fc;
	uint32_t address;
	uint32_t npoint;
	uint32_t poll_time;
	uint32_t OnChange;
	uint32_t OnCMD;
	uint32_t max_error;
	uint32_t position;
	uint32_t start_bit;
	uint32_t swap;
	uint32_t swapword;	

}WRITE_TABLE_STRUC_T;

typedef struct
{
	uint32_t table_number;
	WRITE_TABLE_STRUC_T write_table[MODBUS_WRITE_MAX];

}MODBUS_WRITE_STRUC_T;


//For CFG

typedef struct
{
	CFG_COMMUN_STRUC_T cfg_commun;
	OPC_UA_ACCESS_STRUC_T opcua_access;
	MODBUS_READ_STRUC_T modbus_read;
	MODBUS_WRITE_STRUC_T modbus_write;
	
}GATE_CFG_STRUC_T;



void parse_cfg_init(void);

void opcua_task(void *arg);



#endif /* PARSE_CFG_TASK_H */

